var GlassesForm = function () {
  var template = /* html */ `
    <div class="glasses-form" v-loading.fullscreen.lock="loading">
      <div style="margin-bottom:10px">
        <el-button size="medium" type="primary" @click="ensure">添加</el-button>
      </div>
      <div class="glasses-form-table-div">
        <el-table fit stripe border :data="materialList" style="width: 100%" height="parent" @selection-change="toSelectMaterial" ref="materialTable">
          <el-table-column :resizable="false" width="40px" type="selection" align="center"></el-table-column>
          <el-table-column label="物料类型" prop="materialType" min-width="120px" header-align="center"></el-table-column>
          <el-table-column label="物料名称" prop="materialName" min-width="120px" header-align="center"></el-table-column>
          <el-table-column label="物料规格" prop="model" min-width="120px" header-align="center"></el-table-column>
          <el-table-column label="供应商" prop="providerName" min-width="120px" header-align="center"></el-table-column>
        </el-table>
      </div>
    </div>
  `;

  return {
    props: {
      orderForm: {
        type: Object,
        required: true
      },
      type: {
        type: String,
        default: 'add'
      }
    },

    data: function () {
      return {
        loading: false,
        materialList: [],
        selectMaterialList: []
      };
    },

    created: function () {
      this.setMaterialList();
    },

    methods: {
      setMaterialList: function () {
        this.loading = true;
        var self = this;
        var glassesMaterialList = this.orderForm.glassesMaterialList;
        glassesMaterialList = _.map(glassesMaterialList, 'materialCode');
        ajaxRequest('basicData/queryMaterialCompany', {
          view: 1,
          fullMaterialName:'老花镜'
        }, false).then(function (res) {
          var materialList = res.returnData;
          self.materialList = materialList;
          self.loading = false;
        }).catch(function () {
          self.loading = false;
        });
      },

      toSelectMaterial: function (materialList) {
        this.selectMaterialList = materialList;
      },

      ensure: function () {
        var materialList = this.selectMaterialList;
        if (materialList.length === 0) {
          this.$alert('请选择需要添加的老花镜', '信息');
          return;
        }

        this.orderForm.addGlassesList(materialList);
        this.$emit('add-success');
      }
    },

    template: template
  };
}();
